﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls.CommonTables.SC.CDTY
{
    /// <summary>
    /// ShuHouZhengTongCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class ShouShuHuLiCtrl : CustomCommonTableCtrl
    {
        public ShouShuHuLiCtrl()
        {
            InitializeComponent();
            IniteRadioBation();
            this.Loaded += ShouShuHuLiCtrl_Loaded;
            kssj.GotFocus += Kssj_GotFocus; kssj2.GotFocus += Kssj_GotFocus;
            jssj.GotFocus += Kssj_GotFocus; jssj2.GotFocus += Kssj_GotFocus;
            JTF40.GotFocus += Kssj_GotFocus; JTF43.GotFocus += Kssj_GotFocus;
            JTF46.GotFocus += Kssj_GotFocus; JTF49.GotFocus += Kssj_GotFocus;
            JTF52.GotFocus += Kssj_GotFocus; JTF55.GotFocus += Kssj_GotFocus;
        }
        private void IniteRadioBation()
        {
            new RadioButtonHelper().ChangeRadioSatus(JCB24, JCB25);
            new RadioButtonHelper().ChangeRadioSatus(JCB26, JCB27);
            new RadioButtonHelper().ChangeRadioSatus(JCB28, JCB29);
            new RadioButtonHelper().ChangeRadioSatus(JCB30, JCB31);
            new RadioButtonHelper().ChangeRadioSatus(JCB32, JCB33);
            new RadioButtonHelper().ChangeRadioSatus(JCB34, JCB35);
            new RadioButtonHelper().ChangeRadioSatus(JCB36, JCB37);
            new RadioButtonHelper().ChangeRadioSatus(JCB38, JCB39);
            new RadioButtonHelper().ChangeRadioSatus(qj, qjw);
            new RadioButtonHelper().ChangeRadioSatus(jnsyy, jnsyw);

        }


        private void Kssj_GotFocus(object sender, RoutedEventArgs e)
        {
            CustomTextCtrl custext = sender as CustomTextCtrl;
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;

            cusDatePicker.ShowDialog();

            if (cusDatePicker.Result)
            {
                custext.Value = cusDatePicker.SelectedDateTime.ToString(DateFormat.DATE_FORMAT_STR_HM);//2005年11月5日
            }
        }

        private void ShouShuHuLiCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            DateTime sskssjj = DataManager.Instance.CurrentPatientLink.Status.OperStartTime;
            DateTime ssjssjj = DataManager.Instance.CurrentPatientLink.Status.OperEndTime;
            DateTime sscssjj = DataManager.Instance.CurrentPatientLink.Status.OutRoomTime;
            DateTime rssssjj = DataManager.Instance.CurrentPatientLink.Status.InRoomTime;
            DateTime JTF40j = DataManager.Instance.CurrentPatientLink.Status.OutRoomTime;
            if (!sskssjj.Equals(new DateTime()))
            {
                sskssj.Text = Convert.ToDateTime(sskssjj).ToString("HH:mm");
            }
            if (!ssjssjj.Equals(new DateTime()))
            {
                ssjssj.Text = Convert.ToDateTime(ssjssjj).ToString("HH:mm");
            }
            if (!sscssjj.Equals(new DateTime()))
            {
                sscssj.Text = Convert.ToDateTime(sscssjj).ToString("HH:mm");
            }
            if (!rssssjj.Equals(new DateTime()))
            {
                rssssj.Text = Convert.ToDateTime(rssssjj).ToString("HH:mm");
            }
            if (!JTF40j.Equals(new DateTime()) && string.IsNullOrEmpty(JTF40.Value as string))
            {
                JTF40.Value = Convert.ToDateTime(JTF40j).ToString("HH:mm");
            }




            // 

        }
        

        private void sssj_GotFocus(object sender, RoutedEventArgs e)
        {
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;

            cusDatePicker.ShowDialog();

            if (cusDatePicker.Result)
            {
                sssj.Value = cusDatePicker.SelectedDateTime;//2005年11月5日
            }
        }

        private void rssj_GotFocus(object sender, RoutedEventArgs e)
        {
            CusDatePickerWin cusDatePicker = new CusDatePickerWin();
            cusDatePicker.SelectedDateTime = DateTime.Now;

            cusDatePicker.ShowDialog();

            if (cusDatePicker.Result)
            {
                sssj.Value = cusDatePicker.SelectedDateTime;//2005年11月5日
            }
        }

        private void qxdTimeValueChanged(object sender, EventArgs e)
        {
            string startTime = kssj.Value as string;
            string endTime = jssj.Value as string;
            int startMin = haha(startTime);
            int endMin = haha(endTime);
            if (startMin > 0 && endMin > 0)
            {
                if (endMin - startMin < 0)
                    endMin += 24 * 60;
                string shichang = ((endMin - startMin) / 60).ToString() + "时" + ((endMin - startMin) % 60).ToString() + "分";
                shichang1.Value = shichang;
            }

        }

        private void qxd2TimeValueChanged(object sender, EventArgs e)
        {
            string startTime = kssj2.Value as string;
            string endTime = jssj2.Value as string;
            int startMin = haha(startTime);
            int endMin = haha(endTime);
            if (startMin > 0 && endMin > 0)
            {
                if (endMin - startMin < 0)
                    endMin += 24 * 60;
                string shichang = ((endMin - startMin) / 60).ToString() + "时" + ((endMin - startMin) % 60).ToString() + "分";
                shichang2.Value = shichang;
            }

        }

        private int haha(string time)
        {
            int shichang = 0;
            try
            {
                string[] s = time.Split(':');
                int h = int.Parse(s[0]);
                int min = int.Parse(s[1]);
                shichang = h * 60 + min;
            }
            catch (Exception e)
            {

            }
            return shichang;
        }
    }
}
